/**
 * @(#) TeamWorkListProxy.as
 *
 * @date		2009. 02. 12.
 * @version		1.0
 * @author		Shin, Yunwoo
 * @description	 국경일 및 휴일정보 Proxy - Proxy
 * 				월별 국경일 및 휴일 정보를 가져온다.
 */
package com.skt.common_hr.teamworktime_sac.model
{
	import com.skt.common_hr.common.puremvc.CommonProxy;
	import com.skt.common_hr.teamworktime_sac.model.vo.ReqVacationListVO;
	import com.wcl.utils.DateUtil;
	import com.wcl.utils.StringUtil;
	
	import mx.collections.ArrayCollection;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	
	public class TeamWorkListProxy extends CommonProxy
	{
		public static const NAME:String = "TeamWorkListProxy";

		public static const LOAD_TEAMWORKLIST_COMPLETE:String = "loadTeamWorkListComplete";
		public static const LOAD_TEAMWORKLIST_FAILED:String = "loadTeamWorkListFailed";
		
		public var workTimeList:ArrayCollection;
				
		/**
		 * 생성자
		 * 
		 * @param
		 * @return void
		 */
		public function TeamWorkListProxy(data:Object=null)
		{
			super(NAME, data);
		}
		
		
		/**
		 * data load를 수행
		 * 		- DataLoader 를 생성하고 Import Parameter 객체를 생성, RFC를 호출
		 * 
		 * @param pernr 사번,대상월
		 * @return void
		 */
		public function load(orgCode:String, s:Date, e:Date):void
		{
			var param:Object = new Object();
			param["I_ORGEH"] 	= orgCode;
			param["I_BEGDA"]	= DateUtil.toBasicString(s);
			param["I_ENDDA"]	= DateUtil.toBasicString(e);
			loadData("Z_HR_0201", param, result, fault); 
		}
		
		
		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Event Listeners
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 * 서버에서 정상적으로 리턴된 결과를 처리
		 * 
		 * @param
		 * @return void
		 */
		public function result(event:ResultEvent):void
		{
			if(retCode==0) {  
				workTimeList = parseWorTimeList(event.result.CALTAB2);
				facade.sendNotification(LOAD_TEAMWORKLIST_COMPLETE, this);
			}
			else {
				trace( "failed to get post list");
				facade.sendNotification(LOAD_TEAMWORKLIST_FAILED, this);
			}
		}
		
		/**
		 * 서버에서 오류가 발생했을 처리
		 * 
		 * @param
		 * @return void
		 */
		private function fault(event:FaultEvent):void
		{
			trace(event.fault.faultString);
			facade.sendNotification(LOAD_TEAMWORKLIST_FAILED, this);
		}
		
		
		
		
		
		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Data Parsing functions
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 * 서버에서 전달된 result 객체를 분석하여 Value Object를 생성
		 * 
		 * @param
		 * @return 제증명서 종류 Code list
		 */
		private function parseWorTimeList(srcArr:ArrayCollection):ArrayCollection
		{
			var retArr:ArrayCollection = new ArrayCollection();
			
			for each(var rec:Object in srcArr) 
			{
				var vo:ReqVacationListVO = new ReqVacationListVO();
				vo.PERNR = StringUtil.trimFront(rec.PERNR, "0");		// 사원 번호
				vo.ENAME = rec.ENAME;		// 성명
				vo.WGBN = rec.WGBN;			// 결재상태
				vo.WGBNT = rec.WGBNT;		// 결재상태 텍스트
				vo.DGBN = rec.DGBN;			// 휴가/근무 구분명
				vo.DGBNT = rec.DGBNT;		// 휴가/근무 구분명
				vo.AWART = rec.AWART;		// 세부 근무/휴무 유형
				vo.AWATX = rec.AWATX;		// 세부 근무/휴무 유형명
				vo.BEGDA = DateUtil.stringToDateTime(rec.BEGDA);
				vo.ENDDA = DateUtil.stringToDateTime(rec.ENDDA);
				vo.BEGUZ = DateUtil.stringToDateTime(rec.BEGUZ);
				vo.ENDUZ =DateUtil.stringToDateTime( rec.ENDUZ);
				vo.WSTATUS = rec.WSTATUS;	// 결재유형
				vo.WSTATX = rec.WSTATX;
				vo.TEXT1 = rec.TEXT1;
				vo.GWAREKEY = rec.GWAREKEY;
				vo.OT011 = parseFloat(rec.OT011);
				vo.OT012 = parseFloat(rec.OT012);
				vo.OT021 = parseFloat(rec.OT021);
				vo.OT022 = parseFloat(rec.OT022);
		
				retArr.addItem(vo);
			}
			return retArr;	
		}
		
	}
}